//
//  MenuScene.cpp
//  Frog Jump
//
//  Created by Tri Vo on 7/25/13.
//
//

#include "MenuScene.h"
#include "AboutScene.h"
#include "GuideScene.h"
#include "ChooseLevelScene.h"
#include "SettingsScene.h"
#include "CCScale9Sprite.h"
#include "CCControlButton.h"

using namespace cocos2d;
using namespace extension;

bool MenuScene::init() {
    if (!CCLayer::init()) {
        return false;
    }
    CCSize winSize = GameController::getWinSize();
    
    // Background
    CCSprite *pBackground = CCSprite::create(IMG_BACKGROUND_IPHONE_HD);
    
    pBackground->setPosition(CCPointZero);
    pBackground->setAnchorPoint(CCPointZero);
    addChild(pBackground);
    
    // Game title
    CCLabelTTF *pLblTitle = CCLabelTTF::create("Jumping Frog", FONT_TITLE, 56);
    pLblTitle->setPosition(ccp(winSize.width/2, winSize.height/2 + 250));
    addChild(pLblTitle);
    
    // Frog 1024 x 1024
    CCSprite *pFrog = CCSprite::create(IMG_FROG);
    pFrog->setScale(0.4f);
    pFrog->setPosition(ccp(winSize.width - 200, winSize.height - 350));
    addChild(pFrog);
    
    // LilyPad 1
    CCSprite *pLipad1 = CCSprite::create(IMG_TITLE_LILYPAD_1);
    pLipad1->setScale(0.25);
    pLipad1->setPosition(ccp(150,395));
    addChild(pLipad1);

    // LilyPad 2
    CCSprite *pLipad2 = CCSprite::create(IMG_TITLE_LILYPAD_2);
    pLipad2->setScale(0.25f);
    pLipad2->setPosition(ccp(206, 255));
    addChild(pLipad2);

    // LilyPad 3
    CCSprite *pLipad3 = CCSprite::create(IMG_TITLE_LILYPAD_3);
    pLipad3->setScale(0.25f);
    pLipad3->setPosition(CCPointMake(150, 94));
    addChild(pLipad3);
    
    /*
    // Button
    CCMenuItemLabel *pLabel = CCMenuItemLabel::create(CCLabelTTF::create("About", "Arial", 32), this, menu_selector(MenuScene::menuAbout_Clicked));
    CCSprite *pTempSprite = CCSprite::create(IMG_BTN_NORMAL);
    pTempSprite->setScale(0.25f);
    pTempSprite->setAnchorPoint(CCPointZero);
    pTempSprite->setPosition(CCPointZero);
    pLabel->addChild(pTempSprite, -1);
    CCMenu *pMenu = CCMenu::create(pLabel, NULL);
    pMenu->setAnchorPoint(CCPointZero);
    pMenu->setPosition(CCPointMake(300, 300));
    addChild(pMenu);
     */
    
    CCMenuItemFont *pBtnNewGame = CCMenuItemFont::create(STR_PLAY, this, menu_selector(MenuScene::menuNewGame_Clicked));
    CCMenuItemFont *pBtnGuide = CCMenuItemFont::create(STR_GUIDE, this, menu_selector(MenuScene::menuGuide_Clicked));
    CCMenuItemFont *pBtnSettings = CCMenuItemFont::create(STR_SETTINGS, this, menu_selector(MenuScene::menuSettings_Clicked));
    CCMenuItemFont *pBtnAbout = CCMenuItemFont::create(STR_ABOUT, this, menu_selector(MenuScene::menuAbout_Clicked));
    CCMenuItemFont *pBtnExit = CCMenuItemFont::create(STR_EXIT, this, menu_selector(MenuScene::menuExit_Clicked));
    
    CCMenu *pMenu = CCMenu::create(pBtnNewGame, pBtnGuide, pBtnSettings, pBtnAbout, pBtnExit, NULL);
    pMenu->setAnchorPoint(CCPointZero);
    pMenu->setScale(2.0f);
    pMenu->alignItemsVerticallyWithPadding(10);
    pMenu->setPosition(CCPointMake(winSize.width/2, winSize.height/2 - 50));
    addChild(pMenu);
    return true;
}

CCScene* MenuScene::scene() {
    CCScene *scene = CCScene::create();
    MenuScene *layer = MenuScene::create();
    scene->addChild(layer);
    return scene;
}

MenuScene::~MenuScene() {
    
}

void MenuScene::menuAbout_Clicked(CCObject *pSender) {
    GameController::pushScene(AboutScene::scene());
}

void MenuScene::menuNewGame_Clicked(CCObject *pSender) {
    GameController::pushScene(ChooseLevelScene::scene());
}

void MenuScene::menuSettings_Clicked(CCObject *pSender) {
    GameController::pushScene(SettingsScene::scene());
}

void MenuScene::menuGuide_Clicked(CCObject *pSender) {
    GameController::pushScene(GuideScene::scene());
}
